<?php

namespace Biz\model\activity;

use Doraemon\pockets\datebase\BaseDbModel;

class ActivityRegisterShop extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_activity';

    const _DATABASE_ = 'shop_activity';

    const _TABLE_NAME = 'activity_register_shop';

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;

    const STATUS_DESC = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_DELETE => '已删除',
    ];

    public static function getRegsterIdsByShopId($shopId)
    {
        return self::select('register_id', [
            'shop_id' => $shopId,
            'status' => self::STATUS_NORMAL
        ]);
    }


    public static function getShops($registerId,$select='*')
    {
        $list = self::select($select, ['status[!]' => self::STATUS_DELETE, 'register_id' => $registerId]);
        return $list;
    }

    public static function getList($where, $select = '*', $limit = [], $order = [])
    {
        $param = [
            'AND' => $where,
        ];
        if ($limit) {
            $param['LIMIT'] = $limit;
        }
        if ($order) {
            $param['ORDER'] = $order;
        }
        $list = self::select($select, $param);
        return $list;
    }

    public static function insertData($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('插入数据失败');
        }
        return self::id();
    }

    public static function updateData($data, $where)
    {
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('修改数据失败');
        }
        return true;
    }

}